package com.zonhar.autofeed.controller;

import com.zonhar.autofeed.common.R;
import com.zonhar.autofeed.entities.entity.SensorEntity;
import com.zonhar.autofeed.service.SensorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/sensor")
public class SensorController {

    @Autowired
    private SensorService sensorService;

    /**
     *获取传感器列表
     * @return
     */
    @GetMapping("/sensorList")
    public R sensorList(){
       List<SensorEntity> sensorList = sensorService.sensorList();
        return R.ok().put("data",sensorList);
    }

    /**
     * 更新状态
     * @return
     */
    @PostMapping("/updateStat")
    public R updateStat(Long id){
        SensorEntity sensorEntity = sensorService.updateStat(id);
        return R.ok().put("data",sensorEntity);
    }
}
